home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Files / stdFilterHacking / stdFilterHacking.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-12  |  4.2 KB  |  168 lines  |  [TEXT/MPS ]

  1. #include <Dialogs.h>
  2. #include <Controls.h>
  3. #include <QuickDraw.h>
  4. #include <Windows.h>
  5. #include <ToolUtils.h>
  6. #include <OSUtils.h>
  7. #include <Menus.h>
  8. #include <Fonts.h>
  9. #include <resources.h>
  10. #include <Sound.h>
  11. #include <Traps.h>
  12. #include <Gestaltequ.h>
  13. #include <Memory.h>
  14. #include <Scrap.h>
  15. #include <TextEdit.h>
  16.  
  17. /* These are the new Dialog Manager calls described in Tech note #304 */
  18. /* ONLY used if System 7 or later, of course */
  19. pascal OSErr GetStdFilterProc(ModalFilterProcPtr *theProc) = 
  20. {
  21.     0x303C, 0x0203, 0xAA68
  22. };
  23.  
  24.  
  25.  
  26.  
  27. /* Indicates to the dialog manager which item is default.  Will then alias the return key */
  28. /* to this item, and also bold border it for you (yaaaaa!) */
  29. pascal OSErr SetDialogDefaultItem(DialogPtr theDialog, short newItem)
  30. {
  31.     0x303C, 0x0304, 0xAA68
  32. };
  33.  
  34.  
  35.  
  36.  
  37. /* Indicates which item should be aliased to escape or Command - . */
  38. pascal OSErr SetDialogCancelItem(DialogPtr theDialog, short newItem)
  39. {
  40.     0x303C, 0x0305, 0xAA68
  41. };
  42.  
  43.  
  44.  
  45.  
  46. /* Tells the dialog manager that there is an edit line in this dialog, and */
  47. /* it should track and change to an I-Beam cursor when over the edit line */
  48. pascal OSErr SetDialogTracksCursor(DialogPtr theDialog, Boolean tracks) = 
  49. {
  50.     0x303C, 0x0306, 0xAA68
  51. };
  52.  
  53.  
  54.  
  55. ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem);
  56. pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem);
  57. void ToggleCheckBox(DialogPtr myDialog,short theItem);
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. enum  {
  68.     /* ok and cancel are already defined in Dialogs.h */
  69.     kMessUpItem = 3,
  70.     kHiliteOK
  71. };
  72. enum  {
  73.  
  74.     kSampleDialog = 128, 
  75.     kMessUpAlert
  76. };
  77.  
  78.  
  79. main()
  80. {
  81.     DialogPtr myDialog = nil;                               /* the dialog wee're using */
  82.     short hitItem = 0;                                      /* hitItem for ModalDialog */
  83.     Rect tempRect;                                          /* these  three are here for all the GetDItem/SetDItem calls*/
  84.     short tempItem;
  85.     Handle tempHandle;
  86.     Boolean tempBool;                                       /* a temporary boolean (now THAT'S a helpful comment */
  87.     /* start up manahers */
  88.     InitGraf((Ptr)&qd.thePort);
  89.     InitFonts();
  90.     InitWindows();
  91.     InitMenus();
  92.     TEInit();
  93.     InitDialogs(nil);
  94.     InitCursor();
  95.     /* get our dialog */
  96.     myDialog = GetNewDialog(kSampleDialog, nil, (WindowPtr)-1);
  97.  
  98.  
  99.  
  100.         SetDialogDefaultItem(myDialog, ok);
  101.         SetDialogCancelItem(myDialog, cancel);
  102.         /* dim the OK button initially */
  103.         HiliteControl(SnatchHandle(myDialog,ok),255);
  104.  
  105.     do {
  106.         ModalDialog((ModalFilterProcPtr)filterIt, &hitItem);
  107.         if(hitItem == kMessUpItem){
  108.         /* bring up an alert to obscure the OK button */
  109.         Alert(kMessUpAlert,nil);
  110.         }
  111.         else{
  112.         if(hitItem == kHiliteOK)
  113.         ToggleCheckBox(myDialog,kHiliteOK);        
  114.         HiliteControl(SnatchHandle(myDialog,ok),GetCtlValue(SnatchHandle(myDialog,hitItem)) ? 0 : 255);
  115.         
  116.         }
  117.     
  118.     }
  119.             while (hitItem != ok && hitItem != cancel);
  120.     DisposDialog(myDialog);
  121.     InitCursor();                                           /* Init to prevent I-beam from hanging around in some circumstances */
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128. }
  129.  
  130.  
  131. pascal Boolean filterIt(DialogPtr inputDialog, EventRecord *myDialogEvent, short *theDialogItem)
  132. {
  133.    ModalFilterProcPtr  theModalProc;  /* address of standard filter */
  134.  
  135.  
  136.    if (/* myDialogEvent->what == activateEvt || */myDialogEvent->what == updateEvt) {
  137.    /* reset the state of the button based on my */
  138.    /* check box.  Use whatever conditions you need to determine the  */
  139.    /* correct highlighting */
  140.     HiliteControl(SnatchHandle(inputDialog,ok),GetCtlValue(SnatchHandle(inputDialog,kHiliteOK)) ? 0 : 255);
  141.  
  142.     } 
  143. /* You must still call through the standard filter for things to work, of course */
  144.    GetStdFilterProc( &theModalProc ) ;
  145.    return ( theModalProc( inputDialog, myDialogEvent, theDialogItem ) );
  146.  
  147. }
  148.  
  149. ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem)
  150. {
  151.     short itemtype;
  152.     Rect itemrect;
  153.     Handle thandle;
  154.     
  155.     GetDItem(thebox, theGetItem, &itemtype, &thandle, &itemrect);
  156.     return((ControlHandle)thandle);
  157. } /* end SnatchHandle */
  158.  
  159.  
  160. void ToggleCheckBox(DialogPtr myDialog,short theItem)
  161. {
  162.  
  163. SetCtlValue(SnatchHandle(myDialog,theItem),GetCtlValue(SnatchHandle(myDialog,theItem)) ? false:true);
  164. }
  165.  
  166.